const mysql = require('mysql');

//  封装一个query方法
const dbconfig = {
    host: '127.0.0.1',
    user: 'root',
    password: '',
    database: 'cxblog',
    port: '3306',
    // 可以同时写多条sql语句
    multipleStatements: true
}

const pool = mysql.createPool(dbconfig)

function query(sql, params) {
    return new Promise(function(resolve, reject) {
        pool.getConnection(function(err, conn) {
            if (err) reject(err);
            conn.query(sql, params, function(err, rows) {
                if (err) reject(err);
                resolve(rows);
                conn.release();
            })
        })
    })
}